#!/usr/bin/env python3
"""
修正后的隧道规则配置代码
这个文件展示了如何正确调用writeTunnelRules函数
"""

# 正确的隧道规则配置代码
def configure_tunnel_rules(p4info_helper, s1, s2, s3):
    """
    配置所有隧道规则的函数
    """
    
    # h1 (10.0.1.1) <-> h2 (10.0.2.2) via s1-s2
    writeTunnelRules(p4info_helper, ingress_sw=s1, egress_sw=s2, 
                     tunnel_id=TUNNEL_IDS['s1_s2_ingress'],
                     dst_eth_addr="08:00:00:00:02:22", 
                     dst_ip_addr="10.0.2.2", 
                     t_port=2)
    
    writeTunnelRules(p4info_helper, ingress_sw=s2, egress_sw=s1, 
                     tunnel_id=TUNNEL_IDS['s2_s1_ingress'],
                     dst_eth_addr="08:00:00:00:01:11", 
                     dst_ip_addr="10.0.1.1", 
                     t_port=2)

    # h1 (10.0.1.1) <-> h3 (10.0.3.3) via s1-s3
    writeTunnelRules(p4info_helper, ingress_sw=s1, egress_sw=s3, 
                     tunnel_id=TUNNEL_IDS['s1_s3_ingress'],
                     dst_eth_addr="08:00:00:00:03:33", 
                     dst_ip_addr="10.0.3.3", 
                     t_port=3)
    
    writeTunnelRules(p4info_helper, ingress_sw=s3, egress_sw=s1, 
                     tunnel_id=TUNNEL_IDS['s3_s1_ingress'],
                     dst_eth_addr="08:00:00:00:01:11", 
                     dst_ip_addr="10.0.1.1", 
                     t_port=2)

    # h2 (10.0.2.2) <-> h3 (10.0.3.3) via s2-s3
    writeTunnelRules(p4info_helper, ingress_sw=s2, egress_sw=s3, 
                     tunnel_id=TUNNEL_IDS['s2_s3_ingress'],
                     dst_eth_addr="08:00:00:00:03:33", 
                     dst_ip_addr="10.0.3.3", 
                     t_port=3)
    
    writeTunnelRules(p4info_helper, ingress_sw=s3, egress_sw=s2, 
                     tunnel_id=TUNNEL_IDS['s3_s2_ingress'],
                     dst_eth_addr="08:00:00:00:02:22", 
                     dst_ip_addr="10.0.2.2", 
                     t_port=3)

    # Read table rules (optional)
    readTableRules(p4info_helper, s1)
    readTableRules(p4info_helper, s2)
    readTableRules(p4info_helper, s3)

# 您原始代码的问题对比：
"""
原始代码问题：
1. 缺少逗号：tunnel_id=TUNNEL_IDS['s1_s2_ingres dst_eth_addr=...
   应该是：tunnel_id=TUNNEL_IDS['s1_s2_ingress'], dst_eth_addr=...

2. 键名拼写错误：'s1_s2_ingres' 
   应该是：'s1_s2_ingress'

3. 引号不匹配：TUNNEL_IDS['s1_s2_ingres dst_eth_addr="08:00:00:00:02:22"
   应该是：TUNNEL_IDS['s1_s2_ingress'], dst_eth_addr="08:00:00:00:02:22"
"""